Skip to content

Use an importance score to order the suggested import code action #3271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ChristophHochrainer
Copy link
Contributor

@ChristophHochrainer ChristophHochrainer commented Oct 8, 2022

  • fixes Better ordering for import code actions #3234
  • creates an importance score function for import suggestions based on similarity and module length
  • wraps the computed score and the previous result tuple (CodeAction, NewImport) into an ImportSuggestion
  • orders the ImportSuggestion first based on the score in descending order and second based on the import module names in alphabetic order

Before the PR changes:

image

After the PR changes:

image

@ChristophHochrainer ChristophHochrainer force-pushed the feature/3234_order_import_suggestions branch 2 times, most recently from 7727c92 to fc7d687 Compare October 8, 2022 12:43
@fendor
Copy link
Collaborator

fendor commented Oct 8, 2022

Hi! Please include a test, or an example how the behaviour is now improved!

(I've seen how much it is improved, but we want to document it for everyone else as well)

@ChristophHochrainer ChristophHochrainer force-pushed the feature/3234_order_import_suggestions branch 2 times, most recently from e30fdb8 to 8aece66 Compare October 8, 2022 14:55
@ChristophHochrainer ChristophHochrainer force-pushed the feature/3234_order_import_suggestions branch from 8aece66 to f6f1c83 Compare October 9, 2022 11:54
Copy link
Collaborator

@fendor fendor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, awesome!

@fendor fendor added the merge me Label to trigger pull request merge label Oct 10, 2022
@mergify mergify bot merged commit e176eca into haskell:master Oct 10, 2022
Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were we going to get some tests?

data ImportSuggestion = ImportSuggestion !Int !CodeActionKind !NewImport
deriving ( Eq )

instance Ord ImportSuggestion where
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this Ord instance is not lawful because it doesn't compare the CodeActionKind, which is taken into account by the Eq instance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this! I will fix this ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better ordering for import code actions
4 participants